package com.ruoyi.common.utils.comparetime;

import java.util.*;
import java.util.stream.Collectors;

public class TimeUtils {
    public static Date getMinTime(Date Planstarttime,Date Practicestarttime,Date Examstarttime) {
        List<Long> listarr=new ArrayList<>();
        List<TimeKey> listmk=new ArrayList<>();
        if(Planstarttime!=null) {
            TimeKey mk1=new TimeKey();
            mk1.setKey(Planstarttime.getTime());
            mk1.setValue(Planstarttime);
            listmk.add(mk1);
            listarr.add(mk1.getKey());
        }
        if(Practicestarttime!=null) {
            TimeKey mk2 = new TimeKey();
            mk2.setKey(Practicestarttime.getTime());
            mk2.setValue(Practicestarttime);
            listmk.add(mk2);
            listarr.add(mk2.getKey());
        }
        if(Examstarttime!=null) {
            TimeKey mk3 = new TimeKey();
            mk3.setKey(Examstarttime.getTime());
            mk3.setValue(Examstarttime);
            listmk.add(mk3);
            listarr.add(mk3.getKey());
        }
        Collections.sort(listarr);
        if(listarr.size()>0) {
            List<TimeKey> listmktemp = listmk.stream().filter(s -> s.getKey() == listarr.get(0)).collect(Collectors.toList());
            if (listmktemp.size() > 0) {
                return listmktemp.get(0).getValue();
            }
        }
        return null;
    }

    public static Date getMaxTime(Date Planstarttime,Date Practicestarttime,Date Examstarttime) {
        List<Long> listarr=new ArrayList<>();
        List<TimeKey> listmk=new ArrayList<>();
        if(Planstarttime!=null) {
            TimeKey mk1=new TimeKey();
            mk1.setKey(Planstarttime.getTime());
            mk1.setValue(Planstarttime);
            listmk.add(mk1);
            listarr.add(mk1.getKey());
        }
        if(Practicestarttime!=null) {
            TimeKey mk2 = new TimeKey();
            mk2.setKey(Practicestarttime.getTime());
            mk2.setValue(Practicestarttime);
            listmk.add(mk2);
            listarr.add(mk2.getKey());
        }
        if(Examstarttime!=null) {
            TimeKey mk3 = new TimeKey();
            mk3.setKey(Examstarttime.getTime());
            mk3.setValue(Examstarttime);
            listmk.add(mk3);
            listarr.add(mk3.getKey());
        }
        Collections.sort(listarr, Collections.reverseOrder());
        if(listarr.size()>0) {
            List<TimeKey> listmktemp = listmk.stream().filter(s -> s.getKey() == listarr.get(0)).collect(Collectors.toList());
            if (listmktemp.size() > 0) {
                return listmktemp.get(0).getValue();
            }
        }
        return null;
    }
}
